//
//  WeakProxy.m
//  RXSwiftDemo
//
//  Created by xiaogxjkz on 2022/1/26.
//

#import "WeakProxy.h"

@implementation WeakProxy

- (instancetype)initWithTarget:(id)target {
    _target = target;
    return self;
}

+ (instancetype)initWithTarget:(id)target{
    return [[WeakProxy alloc] initWithTarget:target];
}

//获得调用方法的签名，必须实现
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel{
    if (_target != nil) {
        return [_target methodSignatureForSelector:sel];
    }
    return [super methodSignatureForSelector:sel];
}

//为调用设置目标,必须实现
- (void)forwardInvocation:(NSInvocation *)invocation{
    if (_target != nil) {
        [_target forwardInvocation:invocation];
    }
}

- (id)forwardingTargetForSelector:(SEL)selector {
    return _target;
}

@end
